﻿// 落雪效果
// idea : 可否使用其他影片 or 圖片取代 雪花.

package com.cf.design.effect{
	import flash.display.Sprite;
	import flash.events.Event;
	import com.cf.design.effect.FreeFall;
	import com.cf.core.Utils.tools;
	import com.cf.core.view.MySprite;
	public class Snow extends Sprite{
		private var __num:int=0;
		private var __max:int=200;
		public function set MAX(_n:int):void{__max=_n}
		public function get MAX():int{return __max}
		private var __child:Array;
		private var __top:Number;
		private var __left:Number;
		private var __right:Number;
		private var __bottom:Number;
		
		public function Snow(){
			__child=new Array;
		}//fn
		/*
		public function addImage(_s:String):void{
			__child[__child.length]=_s;
		}//fn
		public function limit(_n:int):void{
			//limit
		}//fn
		*/
		public function area(_l:Number=0, _t:Number=0, _r:Number=300, _b:Number=300){
			__left=_l;
			__top=_t;
			__right=_r;
			__bottom=_b;
		}//fn
		
		public function Start():void{
			addEventListener(Event.ENTER_FRAME,handleSnow);
		}//fn
		private function handleSnow(e:Event=null):void{
			var _ss:int = Math.floor(Math.random() * 10);
			var _slowdown:Boolean = Boolean(_ss>=7);
			// trace("Snow added ? "+ _slowdown +" :: "+ _ss);
			if (__num<__max && _slowdown) {
				var tmp = new FreeFall;
				tmp.area(__left,__top,__right,__bottom);
				try{
					var _no:int = Math.random()*__child.length;
					//var _fall:* = tools.searchLib( __child[ Math.floor( _no ) ] );
					//if(_fall!=false){ tmp.IMG = _fall; }else{ trace("it's nothing there"); }
				}catch(e){}
				addChild(tmp);
				__num++;
			}//if
		}//fn
		public function stopit():void{
			removeEventListener(Event.ENTER_FRAME,handleSnow);
		}//fn
	}//class
}//package